function [r2,pval] = calc_r2(x,y)

p=polyfit(x,y,1);
f=polyval(p,x);
[r2,junk]=rsquare(y,f);
clear junk;

tab=fitlm(x,y);
pval=tab.Coefficients.pValue;